package com.zeny.xdclass.handler;


import com.zeny.xdclass.common.ResponseResult;
import com.zeny.xdclass.exception.XdclassException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName GlobalExceptionHandler
 * @Description 统一异常处理
 * @Author zeny
 * @Version 1.0
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult error(Exception e) {
        log.error(e.getMessage());
        return ResponseResult.exception().message(e.getMessage());
    }

    @ExceptionHandler(XdclassException.class)
    @ResponseBody
    public ResponseResult error(XdclassException e) {
        log.error(e.getMessage());
        return ResponseResult.exception().message(e.getMessage()).code(e.getCode());
    }
}
